<template>
  <card ref="Card">
    <div slot="header">
      <el-input placeholder="己方订单号" v-model="search.number" style="width: 160px;margin-bottom: 5px" clearable @keyup.enter.native="getData"/>
      <el-input placeholder="收件人姓名" v-model="search.receiverName" class="ml-5" style="width: 140px" clearable @keyup.enter.native="getData"/>
      <el-input placeholder="收件人联系电话" v-model="search.receiverPhone" class="ml-5" style="width: 140px" clearable @keyup.enter.native="getData"/>
      <date-time-picker class="ml-5" :start.sync="search.beginUpdateTime" :end.sync="search.endUpdateTime"/>
      <el-button type="success" @click="getData" class="ml-10">搜索</el-button>
      <el-button type="warning" @click="clearSearch">清空</el-button>
    </div>
    <el-table :data="formData">
      <el-table-column prop="number" label="己方订单号" width="165"></el-table-column>
      <el-table-column prop="otherNumber" label="第三方订单号" width="165"></el-table-column>
      <el-table-column prop="senderName" label="寄件人姓名"></el-table-column>
      <el-table-column prop="senderPhone" label="寄件人联系电话"></el-table-column>
      <el-table-column prop="receiverName" label="收件人姓名"></el-table-column>
      <el-table-column prop="receiverPhone" label="收件人联系电话"></el-table-column>
      <el-table-column label="更新时间" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{scope.row.updateTime | formatDateTime}}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="70">
        <template slot-scope="scope">
          <span>{{$state(scope.row.state)}}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" width="100">
        <template slot-scope="scope">
          <el-button icon="el-icon-view" @click.stop="see(scope.row)"/>
        </template>
      </el-table-column>
    </el-table>
    <pagination ref="Pagination" @update="getData"/>
    <order-detail ref="OrderDetail"/>
  </card>
</template>

<script>
  import DateTimePicker from '@/components/DateTimePicker/index'
  import OrderDetail from '@/views/components/OrderDetail'
  import {pageExpressOrderApi} from '@/api/order'
  import {resetForm} from "@/utils/common";

  export default {
    name: 'Passed',
    components: {DateTimePicker, OrderDetail},
    data() {
      return {
        formData: [],
        /* 搜索 */
        search: {
          number: '',
          receiverName: '',
          receiverPhone: '',
          senderPhone: '',
          beginUpdateTime: '',
          endUpdateTime: '',
          state: null
        },
        sendType: 1, // 寄件类型(0国内寄件 1老挝-中国 2中国-老挝)
        isExamine: 1 // 是否验货（是否添加了快递单号）
      }
    },
    mounted() {
      this.getData()
    },
    methods: {
      // 获取
      getData() {
        let pagination = this.$refs.Pagination;
        let param = {
          current: pagination.current,
          size: pagination.size,
          number: this.search.number,
          receiverName: this.search.receiverName,
          receiverPhone: this.search.receiverPhone,
          senderPhone: this.search.senderPhone,
          beginUpdateTime: this.search.beginUpdateTime,
          endUpdateTime: this.search.endUpdateTime,
          state: this.search.state,
          sendType: this.sendType,
          isExamine: this.isExamine
        };
        if (!param.beginUpdateTime) delete param.beginUpdateTime;
        if (!param.endUpdateTime) delete param.endUpdateTime;
        this.$refs.Card.start();
        pageExpressOrderApi(param).then(result => {
          let response = result.resultParam.expressOrderPage;
          this.formData = response.records;
          pagination.total = response.total;
          this.$refs.Card.stop();
        })
      },
      // 查看详情
      see(obj) {
        let _this = this.$refs.OrderDetail
        _this.visible = true
        _this.obj = obj
      },
      // 清空搜索
      clearSearch() {
        resetForm(this, 'search', null).then(() => {
          this.getData();
        })
      }
    }
  }
</script>
